/*
    Document   : common.js
    Created on : Nov 19, 2012
    Author     : HongDC
*/


// Using $ sign for CSS-like query selection
function $ (selector, el) {
    if (!el) {
        el = document;
    }
    return el.querySelector(selector);
}
function $$ (selector, el) {
    if (!el) {
        el = document;
    }
    return el.querySelectorAll(selector);
}

var forEach = Array.prototype.forEach,
$$ = document.querySelectorAll.bind(document);

var toggle = function(el) {
    if ($(el).style.display == "block") {
        $(el).style.display = "none";
    }
    else {
        $(el).style.display = "block";
    }
}

function removeNode() {
    this.parentNode.removeChild(this);
}

function parseXml(xml) {
    var dom = null;
    if (window.DOMParser) {
        try {
            dom = (new DOMParser()).parseFromString(xml, "text/xml");
        }
        catch (e) {
            dom = null;
        }
    } else if (window.ActiveXObject) {
        try {
            dom = new ActiveXObject('Microsoft.XMLDOM');
            dom.async = false;
            if (!dom.loadXML(xml)) // parse error ..
                window.alert(dom.parseError.reason + dom.parseError.srcText);
        }
        catch (e) {
            dom = null;
        }
    } else alert("cannot parse xml string!");
    return dom;
}

function setXmlHttpRequest() {
    if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest(); // For modern browsers
    } else {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); // For historical browsers
    }
    return xmlhttp;
}

function toggleDialog(eleId) {
    toggle(eleId);
    toggle(".modal");
}

if ($(".activeTab")!=null) {
    if ($(".activeTab").value == "orders") {
        $(".active").className = "";
        $(".menuOrders").className = "active";
    }
}